/**
 * 
 */
package ch.baeni.jee.service;

import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;

import ch.baeni.jee.model.User;

/**
 * Service-Klasse fuer alle Aenderungen an Usern
 * 
 * @author Benjamin
 * 
 */
@Stateless
public class UserService {

	@Inject
	private EntityManager em;

	@Inject
	private Event<User> userEventSrc;

	/**
	 * Benutzer speichern
	 * 
	 * @param user
	 *            Zu speicherner User
	 */
	public void saveUser(User user) {
		em.persist(em.merge(user));
		userEventSrc.fire(user);
	}

	/**
	 * Benutzer loeschen
	 * 
	 * @param user
	 *            Zu loeschender User
	 */
	public void deleteUser(User user) {
		em.remove(em.merge(user));
	}
}